<?php
  
  
    require "../../system/framework.php";   
    
   /* $filename = "/data/rtf/auflistung.rtf";
    
    
    file::createFolder("/code/rtf");
    
    $code = new code();
    $code->compileFile($filename, "/code/rtf/auflistung.rtf", false);

  //  echo "<a href='/code/rtf/auflistung.rtf?table=page&id2=".$_REQUEST['id2']."'>weiter</a>";  */
    
    
    
    $rtfFilename = "/code/rtf/[php_property:rtf_filename]";
 //   http::redirect($rtfFilename);
    
    
    
   
     $path='I:/Daten/snapol/htdocs/com/zendFramework/api';
  set_include_path(get_include_path() . PATH_SEPARATOR . $path);
  
  include_once "I:/Daten/snapol/htdocs/com/zendFramework/api/Zend/Service/LiveDocx/MailMerge.php";  
  
   
  
  $phpLiveDocx = new Zend_Service_LiveDocx_MailMerge(
    array (
        'username' => 'urslang',
        'password' => 'baarburg99'
    )
); 


global $rootDir;

//$docFilename = $rootDir."/com/ZendFramework/template.docx";
$docFilename = $rootDir."/code/rtf/auflistung.rtf?table=page&id2=".$_REQUEST['id2'];
                                                                                                                              //.$_REQUEST['id2']
$rtfContent = http::httpGet("http://localhost/code/rtf/auflistung.rtf?table=page&id2=84739d793583d247c33dd07f289c3f8fef57e4ea");

file::createTextFile("/tmp/file1.rtf", $rtfContent);

$docFilename = $rootDir."/tmp/file1.rtf";    


//$phpLiveDocx->setLocalTemplate('template.docx');
$phpLiveDocx->setLocalTemplate($docFilename);


//$phpLiveDocx->setLocalTemplate('template2.doc');

//$phpLiveDocx->assign('name', 'Lang');
//$phpLiveDocx->assign('vorname', 'Urs');
//$phpLiveDocx->assign('company',  'Megasoft Co-operation');

/*
$billConnections = array (
    array ('name' => 'Lang', 'vorname' => 'Urs'),
    array ('name' => 'Klang', 'vorname' => 'Kurs')
    
);
 
$phpLiveDocx->assign('block1', $billConnections);  */




  
$phpLiveDocx->createDocument();

$document = $phpLiveDocx->retrieveDocument('pdf');


$pdfFilename = "$rootDir/tmp/doc2.pdf";

//file_put_contents('document.pdf', $document);
file_put_contents($pdfFilename, $document);
//stream_context_create($document);



    header("Content-type: application/pdf");
  
  header("Content-Disposition: attachment; filename=doc2.pdf");
  header("Pragma: no-cache");
  header("Expires: 0");
  readfile($pdfFilename);

  unset($phpLiveDocx);
    
    
      
    
    
    
    
    
    
  
?>
